﻿
@{
    var dbcontext = new alguillet_ExpenseManagerEntities();
    var friends = new Dictionary<Member, MembersRelation>();
    var iFriends = new Dictionary<Member, MembersRelation>();
    var theyFriends = new Dictionary<Member, MembersRelation>();
    var curruser = dbcontext.Members.Where(user => user.IDMember == WebSecurity.CurrentUserId).First();
    var iReq = curruser.iRequested.Where(rel => rel.Status == 1);
    var theyReq = curruser.theyRequested.Where(rel => rel.Status == 1);
    var iReqWaiting = curruser.iRequested.Where(rel => rel.Status == 0);
    var theyReqWaiting = curruser.theyRequested.Where(rel => rel.Status == 0);
    foreach (var relation in iReq)
    {
        friends.Add(relation.Members1, relation);
    }
    foreach (var relation in theyReq)
    {
        friends.Add(relation.Members, relation);
    }    
    foreach (var relation in iReqWaiting)
    {
        iFriends.Add(relation.Members1, relation);
    }
    foreach (var relation in theyReqWaiting)
    {
        theyFriends.Add(relation.Members, relation);
    }
}

<h4>
    Your Friends</h4>
@if (friends.Count() > 0)
{
    <text>You have @friends.Count() @if (@friends.Count() > 1)
                                    {<text>friends</text>}
                                    else
                                    {<text>friend</text>}.
    <table>
        <tr>
            <th>
                Member name
            </th>
            <th>
                Since
            </th>
        </tr>
        @foreach (var friend in friends.OrderBy(f => f.Key.Login))
        {
            <tr>
                <td>@friend.Key.Login
                </td>
                <td>@friend.Value.DateAccepted.Value.ToShortDateString()
                </td>
            </tr>
        }
    </table>
    </text>
}
else
{
    <text>You have no friends, you fucking shower sac !</text>
}

<br />
<br />

@if (@iFriends.Count() > 0)
{
    <text>Contact @if (@iFriends.Count() > 1){<text>requests</text>}else{<text>request</text>} sent waiting : @iFriends.Count() 
    <table>
        <tr>
            <th>
                Member name
            </th>
            <th>
                Since
            </th>
        </tr>
        @foreach (var friend in iFriends)
        {
            <tr>
                <td>@friend.Key.Login
                </td>
                <td>@friend.Value.DateRequested
                </td>
            </tr>
        }
    </table>
    </text>
}
else
{
    <text>You didn't send request !</text>
}

<br />
<br />
    
@if (@theyFriends.Count() > 0)
{
    <text>Contact @if (@theyFriends.Count() > 1)
                  {<text>requests</text>}
                  else
                  {<text>request</text>} recieved waiting : @theyFriends.Count() 
    <table>
        <tr>
            <th>
                Member name
            </th>
            <th>
                Since
            </th>
        </tr>
        @foreach (var friend in theyFriends)
        {
            <tr>
                <td>@friend.Key.Login
                </td>
                <td>@friend.Value.DateRequested
                </td>
                <td><span data-id='@friend.Value.IDRelation' class='acceptfriendrequestbutton' >V</span></td>
                <td><span data-id='@friend.Value.IDRelation' class='declinefriendrequestbutton' >X</span></td>
            </tr>
        }
    </table>
    </text>
}
else
{
    <text>None asked you to be friend, you fucking shower sac !</text>
}